package com.zhixiang.xaec.action.safebase.safemeeting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.zhixiang.core.command.QueryFilter;
import com.zhixiang.core.entity.TreeObj;
import com.zhixiang.core.util.BeanUtil;
import com.zhixiang.core.util.YearGridCrud;
import com.zhixiang.core.web.action.BaseAction;
import com.zhixiang.xaec.entity.safebase.safemeeting.MeetManage;
import com.zhixiang.xaec.service.safebase.safemeeting.MeetManageService;

@Controller
@Scope("prototype")
public class MeetManageAction extends BaseAction {

	/**
	 * 意义，目的和功能，以及被用到的地方<br>
	 */
	private static final long serialVersionUID = 2312465282938701795L;

	private MeetManage meetManage;

	@Autowired
	private MeetManageService meetManageService;


    public MeetManage getMeetManage()
    {
        return meetManage;
    }

    public void setMeetManage(MeetManage meetManage)
    {
        this.meetManage = meetManage;
    }
    
    public String list(){
        
        QueryFilter localQueryFilter = new QueryFilter(getRequest());
        List<MeetManage>localList = this.meetManageService.getAll(localQueryFilter);         
        setSuccess(true);
        setTotalCounts(localQueryFilter.getPagingBean().getTotalItems());
        //返回结果集
        setResult(localList);
        return SUCCESS;
    }
    
    public String get(){
        String id = getRequest().getParameter("id");
        if(!"".equals(id)&&id!=null){
            setResult(meetManageService.get(Long.valueOf(id)));
        }
        return SUCCESS;
    }
    
    public String delete(){
		try {
			String[] ids = getRequest().getParameterValues("ids");
	        meetManageService.delete(ids);
		} catch (Exception e) {
			 setMsg("删除失败");
			 setSuccess(false);
		}
        return SUCCESS;     
    } 
    
    public String save(){
    try {
	    if(meetManage.getId()!=null){
	    	MeetManage mm=meetManageService.get(meetManage.getId());
	    	BeanUtil.copyNotNullProperties(mm, meetManage);
	    	meetManageService.save(mm);
	    }else{
	    	meetManageService.save(meetManage);	
	    }
    
	} catch (Exception e) {
		 setMsg("保存失败");
		 setSuccess(false);
	}       
    	
        return SUCCESS;
    }
    
  /*  public String treeLoad(){
        String id = getRequest().getParameter("nodeId");
        if("".equals(id)||id==null){
            id="1";
        }
        List<TreeObj> treeList=meetManageService.treeLoad(id);
        //直接向页面输出字符串
        if(treeList!=null){
            outJsonString(new Gson().toJson(treeList));
        }       
        return SUCCESS;
    }*/
    public String treeLoad() {
		List<TreeObj> treeList = YearGridCrud.treeLoad();
		if (treeList != null) {
			outJsonString(new Gson().toJson(treeList));
		}
		return SUCCESS;
	}
}
